if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetLogItemsForCOI]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetLogItemsForCOI]
GO

/******************************************************************
* Name:			GetLogItemsForCOI
* Purpose:		Retrieves the LogItem for the given COI Id
*					
*
* PARAMETERS
* Name    				Description					
* -------------  		----------------------------------
* @coiId			Id of the COI
******************************************************************/

CREATE PROCEDURE [dbo].[GetLogItemsForCOI]
(
@coiId	int			
)
AS
BEGIN

	SET NOCOUNT ON

			Select	[Id],
				[QuestionnaireVersionId],
				[QuestionnaireAnswerId],
				[Type],
				[Category],
				[QuestionName],
				[Answer],
				[Description],
				[Completed]
				
					
			FROM LogItem LI INNER JOIN COI_LogItem_Map Map ON LI.Id = Map.LogItemId

			WHERE Map.[COIId] = @coiId  
	
END

